import React, { Component } from 'react'
import "./index.css"
import Count from '../1_setState'

export default class Demo extends Component {
  render() {
    return (
      <div className="parent">
        我是父组件...
        {/* 让A组件成为B组件的父亲的另一种方式 */}
        <A render={(count)=><Count x={count}/>}/>
      </div>
    )
  }
}


class A extends Component {
  state={name: 'tome', count: 1}
  render() {
    const {name, count} = this.state
    return (
      <div className="child">
        我是组件A
        {this.props.render(count)}
      </div>
    )
  }
}

class B extends Component {
  render() {
    return (
      <div className="grand">
        我是组件B, 我的名字是：{this.props.name}
      </div>
    )
  }
}
